package com.wgchao.identityrightsmanagement.infrastructure.convert;

import com.wgchao.identityrightsmanagement.domain.organization.model.Address;
import com.wgchao.identityrightsmanagement.domain.organization.model.Agency;
import com.wgchao.identityrightsmanagement.infrastructure.jpa.entity.SysBaseAgency;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

/**
 * @ClassName: AgencyConvert
 * @author: wgchao
 * @createTime: 2020/6/11 5:03 PM
 * @Description: TODO
 */
@Component
public class AgencyConvert {

    public Agency convert(SysBaseAgency sysBaseAgency){
        Agency agency = new Agency(sysBaseAgency.getId(), sysBaseAgency.getAgencyCode(), sysBaseAgency.getAgencyName(),
                new Address(sysBaseAgency.getProvince(), sysBaseAgency.getCity(), sysBaseAgency.getCounty(), sysBaseAgency.getXxaddress()),
                sysBaseAgency.getDescription(), sysBaseAgency.getDisabled(), sysBaseAgency.getVersion());
        return agency;
    }

    public SysBaseAgency convert(Agency agency){
        SysBaseAgency sysBaseAgency = new SysBaseAgency();
        BeanUtils.copyProperties(agency, sysBaseAgency);
        sysBaseAgency.setProvince(agency.getAddress().getProvince());
        sysBaseAgency.setCity(agency.getAddress().getCity());
        sysBaseAgency.setCounty(agency.getAddress().getCounty());
        sysBaseAgency.setXxaddress(agency.getAddress().getXxaddress());
        return sysBaseAgency;
    }

}
